package models

import (
	"github.com/Hougir/utils/time"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
)

type BaseModel struct {
	Id        int       `json:"id"`
	IsDelete  int       `json:"isDelete"`
	CreatedAt time.Time `json:"createdAt" orm:"auto_now_add;type(datetime);null"` //auto_now_add第一次保存时才设置时间,可为空
	UpdatedAt time.Time `json:"updatedAt" orm:"auto_now;type(datetime);null"`     //auto_now每次model保存时都会对时间自动更新,可为空
	DeletedAt time.Time `json:"deletedAt"`
}

func Init() {
	dbhost := beego.AppConfig.String("dbhost")
	dbport := beego.AppConfig.String("dbport")
	dbuser := beego.AppConfig.String("dbuser")
	dbpassword := beego.AppConfig.String("dbpassword")
	dbname := beego.AppConfig.String("dbname")
	if dbport == "" {
		dbport = "3306"
	}
	dsn := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?charset=utf8&loc=Asia%2FShanghai"
	orm.RegisterDataBase("default", "mysql", dsn)
	orm.RegisterModel(new(User))
}

// //返回带前缀的表名
//
//	func TableName(str string) string {
//	 return beego.AppConfig.String("dbprefix") + str
//	}
